require(['init'], function () {
  var comments=UE.getEditor('comments');
  var replyid  = location.search.urlToObj().replyid;
  var studentuid=location.search.urlToObj().studentuid;
  var taskid=location.search.urlToObj().taskid;
  var studentname=location.search.urlToObj().studentname;
  var classe=location.search.urlToObj().classe;
   //获取老师布置作业和上课的返回信息
  $.ajax({
       url:'/api/task/subject/'+taskid,
       type:'get',
       success:function(data){
         var data=data.data;
         var classeid=data.classeid;
         var scheduleid=data.scheduleid;
          $('.oldcontent').html(data.content);
          $('.title').html(data.title);
          $('.oldnote').html(data.note);
          $('#wrap').find('a').attr('target','_blank');
        if(data.classetype==2){
           $.ajax({
             url:'/api/classe/'+classeid,
             type:'get',
             success:function(json){
               console.log(json)
               $('.classname').html(json.data.classname)
             }
           })

         }else if(data.classetype==1){
           $('.classname').html("约课");
         }
         $.ajax({
           url:'/api/schedule/'+scheduleid,
           type:'get',
           success:function(datat){
            $.each(datat,function(int,ite){
            $('.lessonname').html(ite.name)

            })

           }
         })
     }
  })
  //获取学生的答案
  $.ajax({
   url:'/api/task/student/reply',//get /api/task/student/reply
   data:{
     taskid:taskid,
     studentuid:studentuid
   },
   success:function(data){
     $.each(data.data,function(index,item){
       if(item.type==1){
        var replyat;
        if(item.replyat!=null){
         replyat=$.toDate(item.replyat).Format('YYYY-MM-DD hh:mm:ss').substr(11,5);
        }
         $('.currenttime').html(replyat);
         $('  <div class="formLi">\
               <div class="formTitle">\
                   <span style="color:#818e9b">学生答案</span></br>\
                   <span style="color:#818e9b" class="studentname">'+studentname+'</span></br>\
                   <span style="color:#818e9b" class="currenttime">'+replyat+'</span>\
               </div>\
               <div class="formContent">\
                   <span class="student_answer">'+item.content+'</span>\
               </div>\
           </div>').appendTo($('.job_content'))
       }else if(item.type==2){
         $('<div class="formLi">\
               <div class="formTitle">\
                   <span style="color:#818e9b">老师回复</span></br>\
                   <span style="color:#818e9b" class="studentname">张三</span></br>\
               </div>\
               <div class="formContent">\
                   <span class="student_answer">'+item.content+'</span>\
               </div>\
           </div>').appendTo($('.job_content'))
       }


     })

   }
  })
  $('.wrap').find('a').attr('target','_blank');
  reply_job();
  function reply_job(){
    $('.reply').on('click',function(){
      $('.submit').show();
      $('.edit').show();
      $(this).hide();
      var $submit_html=$('#submit_html');
      $submit_html.on('click',function(){
      var content=comments.getContent();
      if(content!=""){
        $('#notesubmit').hide();
        ajaxMethod({
          url: '/api/task/reply/'+replyid+'/correct',
          type: 'put',
          data: {
            content:content,
          },
          success: function (data) {
           window.location.href = "jobs_list.html?taskid="+taskid+"&classe="+classe+"";
          }
        })
      }else{
        $('#notesubmit').show();
        return false;
      }

      })
    })
  }

})
